package org.yzh.web.mp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.yzh.protocol.commons.transform.attribute.AlarmDSM;
import org.yzh.web.mp.entity.Alarm65;
import org.yzh.web.mp.mapper.TaosAlarm65Mapper;
import org.yzh.web.mp.service.TaosAlarm65Service;

/**
 * @author nick
 * @description 65报警ServiceImpl
 * @date 2022/6/14
 **/
@Service
@AllArgsConstructor
public class TaosAlarm65ServiceImpl extends ServiceImpl<TaosAlarm65Mapper, Alarm65> implements TaosAlarm65Service {

    private final TaosAlarm65Mapper alarm65Mapper;

    @Override
    public Boolean insert(Alarm65 model) {
        return alarm65Mapper.insertOne(model) > 0;
    }


    /**
     * 获取65报警的类型（驾驶员状态）
     *
     * @param item T0200
     * @return 报警类型
     */
//    @Override
//    public CloudAlarm6465InfoModel getAlarm65Type(T0200 item) {
//        return this.getCloudAlarm6465InfoModel(item);
//    }
//
//    private CloudAlarm6465InfoModel getCloudAlarm6465InfoModel(T0200 item) {
//        if (item.getAttributes().get(SysConst.ATTRIBUTE_DMS_INDEX) != null) {
//            CloudAlarm6465InfoModel alarm6465InfoModel = new CloudAlarm6465InfoModel();
//            AlarmDSM adas = (AlarmDSM) item.getAttributes().get(SysConst.ATTRIBUTE_DMS_INDEX);
//            alarm6465InfoModel.setEventType(adas.getType());
//            alarm6465InfoModel.setAttachments(adas.getFileTotal());
//            alarm6465InfoModel.setAlarmId(String.valueOf(adas.getId()));
//            alarm6465InfoModel.setAlarmLevel(adas.getLevel());
//            return alarm6465InfoModel;
//        }
//        return null;
//    }


    /**
     * 插入65报警（DMS）
     *
     * @param vehicleId 车辆id
     * @param alarmDms  Dms实体
     */
    @Override
    public void insertAlarm65(String vehicleId, AlarmDSM alarmDms) {
        // TD dms报警
        this.insert(this.toAlarm65(alarmDms, vehicleId));
    }


    private Alarm65 toAlarm65(AlarmDSM alarmDms, String vehicleId) {
        // TD dms报警
        return this.getAlarm65(alarmDms, vehicleId);
    }

    private Alarm65 getAlarm65(AlarmDSM alarmDms, String vehicleId) {
        Alarm65 alarm65 = new Alarm65();
        return alarm65.populateAlarmFields(vehicleId, alarmDms.getType(), alarmDms.getLevel(), alarmDms.getId(), alarmDms.getFileTotal(), alarmDms.getDateTime(), alarmDms.getLongitude() / 1000000.0, alarmDms.getLatitude() / 1000000.0, alarm65);
    }


}
